use napi_derive_ohos::napi;
use sled::Db;

#[napi]
pub fn open_db(path: String) -> String {
    match sled::open(path) {
        Ok(_) => "成功打开数据库".to_string(),
        Err(e) => format!("打开数据库失败: {}", e),
    }
}

#[napi]
pub fn insert_data(path: String, key: String, value: String) -> String {
    match sled::open(path) {
        Ok(db) => {
            if let Err(e) = db.insert(key.as_bytes(), value.as_bytes()) {
                return format!("插入失败: {}", e);
            }
            "插入成功".to_string()
        }
        Err(e) => format!("打开数据库失败: {}", e),
    }
}

